package com.syyo.gulimall.product.app;

//import org.springframework.security.access.prepost.PreAuthorize;

import com.syyo.common.utils.ResultUtils;
import com.syyo.common.valid.AddGroup;
import com.syyo.common.valid.EditGroup;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import com.syyo.gulimall.product.domain.req.BrandReq;
import com.syyo.gulimall.product.service.BrandService;
import com.syyo.common.domain.ResultVo;

import java.util.List;


/**
 * 品牌
 *
 * @author syyo
 * @email syyo@gmail.com
 * @date 2021-01-20 09:32:12
 */
@RestController
@RequestMapping("/product/brand")
public class BrandController {

    @Autowired
    private BrandService brandService;

    /**
     * 新增
     */
    @PostMapping
    // @PreAuthorize("@syyo.check('system:brand:add')")
    public ResultVo add(@Validated({AddGroup.class}) @RequestBody BrandReq req) {
        return ResultUtils.ok(brandService.add(req));
    }

    /**
     * 删除
     */
    @DeleteMapping("/{id}")
    // @PreAuthorize("@syyo.check('system:brand:del')")
    public ResultVo del(@PathVariable("id") Integer id) {
        return ResultUtils.ok(brandService.del(id));
    }

    /**
     * 修改
     */
    @PutMapping
    // @PreAuthorize("@syyo.check('system:brand:edit')")
    public ResultVo edit(@Validated({EditGroup.class}) @RequestBody BrandReq req) {
        return ResultUtils.ok(brandService.edit(req));
    }

    /**
     * 信息
     */
    @GetMapping("/{id}")
    public ResultVo findOne(@PathVariable("id") Integer id) {
        return ResultUtils.ok(brandService.findOne(id));
    }

    /**
     * 信息
     */
    @GetMapping("/infos")
    public ResultVo brandInfos(@RequestParam("ids") List<Long> ids) {
        return ResultUtils.ok(brandService.infos(ids));
    }

    /**
     * 列表
     */
    @GetMapping("/list/{pageNum}/{pageSize}")
    public ResultVo findAll(@PathVariable("pageNum") Integer pageNum,
                            @PathVariable("pageSize") Integer pageSize,
                            BrandReq req) {
        return ResultUtils.ok(brandService.findAll(pageNum, pageSize, req));
    }

}
